Library & Dataset

Using OLR

Inspect Dataset Using Training and Validation

OLR Equations

Inspect Dataset Using Training and Validation

vclust <- varclus (~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil +  TC_weath_rock  + TC_unstable_structure  + T_construction  + spring +  landfill + garbage  + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank  + tree + ground_veg + deforestation + banana + drainage , data=train.data)

# took out density since training has 0 d4 and it was not allowing do the plot

p <- plot(vclust)

par(mfrow=c(6,5))
plot.xmean.ordinaly (risk~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil +  TC_weath_rock  + TC_unstable_structure  + T_construction  + spring +  landfill + garbage  + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank  + tree + ground_veg + deforestation + banana + drainage, data=train.data, cr=TRUE , subn=FALSE)

#angle + building+density+EN +TC + TC_mature_Soil + TC_saprolito +  TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + aterro + lixo + entulho + crack + belly_wall + scars + drawback + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana 

Diagnostic 2: Proportion (-5% of one of the parameters based on what is expected. Since some parameters have 2 predictors, others 5)

#library(plyr)
brick <- count(train.data$brick) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "brick")

wood <- count(train.data$wood) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "wood")

mixed <- count(train.data$mixed) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "mixed")

TC_mature_soil <- count(train.data$TC_mature_soil) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_mature_soil")

T_construction  <- count(train.data$T_construction ) %>%
  mutate ("Percentage"=(freq/265)*100) %>%
  mutate("Classifier" = "T_construction ")

spring <- count(train.data$spring) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "spring")

landfill <- count(train.data$landfill) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "landfill")

garbage <- count(train.data$garbage) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "garbage")

crack <- count(train.data$crack) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "crack")

leaning_wall <- count(train.data$leaning_wall) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "leaning_wall")

scars <- count(train.data$scars) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "DepTaludeAterro")

downward_floor <- count(train.data$downward_floor) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "scars")

tilted <- count(train.data$tilted) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "tilted")

conc_rainfall <- count(train.data$conc_rainfall) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "conc_rainfall")

wastewater <- count(train.data$wastewater) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "wastewater")

leak <- count(train.data$leak) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "conc_rainfall_water")

septic_tank <- count(train.data$septic_tank) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "septic_tank")

angle <- count(train.data$angle) # angle A less than 5% but the rest are okay (3,50, 91, 277, 109) Expected=106
angle <- angle %>%
  mutate("Percentage"=(freq/106)*100)%>%
  mutate("Classifier" = "angle")

EN <- count(train.data$EN) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "EN")

TC <- count(train.data$TC)  %>%
  mutate ("Percentage"=(freq/265)*100) %>%
  mutate("Classifier" = "TC")

TC_saprolite_soil  <- count(train.data$TC_saprolite_soil )  %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_saprolite_soil ")

banana <- count(train.data$banana) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "banana")

drainage <- count(train.data$drainage) %>%
  mutate ("Percentage"=(freq/176.7)*100)%>%
  mutate("Classifier" = "drainage")

deforestation <- count(train.data$deforestation) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "deforestation")

TC_unstable_structure  <- count(train.data$TC_unstable_structure ) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_unstable_structure ")


tree <- count(train.data$tree) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "tree")

ground_veg <- count(train.data$ground_veg) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "ground_veg")


density <- count(train.data$density)  %>% #(79, 415, 36) # d4 =0 
  mutate ("Percentage"=(freq/132.5)*100)%>%
  mutate("Classifier" = "density")

TC_weath_rock  <- count(train.data$TC_weath_rock ) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_weath_rock ")

fracture <- count(train.data$fracture) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "fracture")









df <- rbind(brick, wood, mixed, TC_mature_soil, T_construction, spring, landfill, garbage, crack, leaning_wall, scars, downward_floor, tilted, conc_rainfall, wastewater, leak, septic_tank, angle, EN, TC, TC_saprolite_soil,  banana, drainage, deforestation, TC_unstable_structure, tree, ground_veg,density, TC_weath_rock, fracture)

df
##        x freq  Percentage             Classifier
## 1  FALSE   38  14.3396226                  brick
## 2   TRUE  492 185.6603774                  brick
## 3  FALSE  456 172.0754717                   wood
## 4   TRUE   74  27.9245283                   wood
## 5  FALSE  492 185.6603774                  mixed
## 6   TRUE   38  14.3396226                  mixed
## 7  FALSE  258  97.3584906         TC_mature_soil
## 8   TRUE  272 102.6415094         TC_mature_soil
## 9  FALSE  204  76.9811321        T_construction 
## 10  TRUE  326 123.0188679        T_construction 
## 11 FALSE  511 192.8301887                 spring
## 12  TRUE   19   7.1698113                 spring
## 13 FALSE  329 124.1509434               landfill
## 14  TRUE  201  75.8490566               landfill
## 15 FALSE  346 130.5660377                garbage
## 16  TRUE  184  69.4339623                garbage
## 17 FALSE  448 169.0566038                  crack
## 18  TRUE   82  30.9433962                  crack
## 19 FALSE  500 188.6792453           leaning_wall
## 20  TRUE   30  11.3207547           leaning_wall
## 21 FALSE  317 119.6226415        DepTaludeAterro
## 22  TRUE  213  80.3773585        DepTaludeAterro
## 23 FALSE  467 176.2264151                  scars
## 24  TRUE   63  23.7735849                  scars
## 25 FALSE  425 160.3773585                 tilted
## 26  TRUE  105  39.6226415                 tilted
## 27 FALSE   19   7.1698113          conc_rainfall
## 28  TRUE  511 192.8301887          conc_rainfall
## 29 FALSE  210  79.2452830             wastewater
## 30  TRUE  320 120.7547170             wastewater
## 31 FALSE  333 125.6603774    conc_rainfall_water
## 32  TRUE  197  74.3396226    conc_rainfall_water
## 33 FALSE  528 199.2452830            septic_tank
## 34  TRUE    2   0.7547170            septic_tank
## 35     C   29  27.3584906                  angle
## 36     D  128 120.7547170                  angle
## 37     E  373 351.8867925                  angle
## 38 FALSE  340 128.3018868                     EN
## 39  TRUE  190  71.6981132                     EN
## 40 FALSE   26   9.8113208                     TC
## 41  TRUE  504 190.1886792                     TC
## 42 FALSE  449 169.4339623     TC_saprolite_soil 
## 43  TRUE   81  30.5660377     TC_saprolite_soil 
## 44 FALSE  343 129.4339623                 banana
## 45  TRUE  187  70.5660377                 banana
## 46     Y   67  37.9173741               drainage
## 47     P  233 131.8619128               drainage
## 48     N  230 130.1641200               drainage
## 49 FALSE  495 186.7924528          deforestation
## 50  TRUE   35  13.2075472          deforestation
## 51 FALSE  519 195.8490566 TC_unstable_structure 
## 52  TRUE   11   4.1509434 TC_unstable_structure 
## 53 FALSE  210  79.2452830                   tree
## 54  TRUE  320 120.7547170                   tree
## 55 FALSE  154  58.1132075             ground_veg
## 56  TRUE  376 141.8867925             ground_veg
## 57    d1   66  49.8113208                density
## 58    d2  430 324.5283019                density
## 59    d3   34  25.6603774                density
## 60 FALSE  518 195.4716981         TC_weath_rock 
## 61  TRUE   12   4.5283019         TC_weath_rock 
## 62 FALSE  529 199.6226415               fracture
## 63  TRUE    1   0.3773585               fracture

TC_weath_rock, TC_rock_TC_geol_desf, fracture, TC_rock

Equation 1

f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana , data=train.data, x=TRUE , y=TRUE)

f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank +TC_mature_Soil , data=train.data, x=TRUE , y=TRUE) print (f1 , latex =TRUE , coefs =5) stargazer(anova(f1), type=“text”, style=“default”)

# Equation 1

eq_OLR_01 <- polr(risk ~ brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil, data= train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_01))



p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                             Value Std. Error    t value      p value
## brickTRUE             -1.05496407  0.4555914 -2.3155925 1.029026e-02
## woodTRUE               1.28505800  0.3328812  3.8604108 5.659828e-05
## ENTRUE                 0.67550471  0.3697407  1.8269685 3.385225e-02
## TC_mature_soilTRUE     0.45968566  0.2206572  2.0832571 1.861390e-02
## T_constructionTRUE     0.25183255  0.3618443  0.6959693 2.432240e-01
## springTRUE             0.45300279  0.6186059  0.7322962 2.319939e-01
## landfillTRUE           0.16690916  0.3234762  0.5159859 3.029321e-01
## leakTRUE              -0.05218241  0.2355406 -0.2215431 4.123348e-01
## garbageTRUE            0.21242666  0.2902545  0.7318635 2.321259e-01
## crackTRUE              1.71380934  0.3291884  5.2061651 9.639157e-08
## leaning_wallTRUE       2.32910641  0.5388099  4.3226870 7.707015e-06
## scarsTRUE              3.97101508  0.3565513 11.1372899 4.129726e-29
## downward_floorTRUE     0.81769676  0.3675403  2.2247809 1.304797e-02
## tiltedTRUE             1.28849743  0.3169039  4.0658933 2.392441e-05
## septic_tankTRUE       -1.57300635  1.4252846 -1.1036437 1.348739e-01
## conc_rainfallTRUE      1.58976162  0.5307732  2.9951807 1.371411e-03
## wastewaterTRUE         0.68386836  0.2375188  2.8792183 1.993311e-03
## ground_vegTRUE         0.76923552  0.2556269  3.0092117 1.309633e-03
## angleD                 0.06851177  0.4882918  0.1403091 4.442079e-01
## angleE                 0.40650978  0.5528044  0.7353591 2.310604e-01
## TC_saprolite_soilTRUE  0.43432233  0.2945352  1.4746025 7.015972e-02
## R1|R2                  0.35640040  0.8692838  0.4099931 3.409055e-01
## R2|R3                  4.68198705  0.9145671  5.1193479 1.532969e-07
## R3|R4                  9.80698857  1.0074561  9.7344081 1.075330e-22
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ======================================================
##                       Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE             -1.05    0.46     -2.32   0.01  
## woodTRUE              1.29     0.33     3.86   0.0001 
## ENTRUE                0.68     0.37     1.83    0.03  
## TC_mature_soilTRUE    0.46     0.22     2.08    0.02  
## T_constructionTRUE    0.25     0.36     0.70    0.24  
## springTRUE            0.45     0.62     0.73    0.23  
## landfillTRUE          0.17     0.32     0.52    0.30  
## leakTRUE              -0.05    0.24     -0.22   0.41  
## garbageTRUE           0.21     0.29     0.73    0.23  
## crackTRUE             1.71     0.33     5.21   0.0000 
## leaning_wallTRUE      2.33     0.54     4.32   0.0000 
## scarsTRUE             3.97     0.36     11.14     0   
## downward_floorTRUE    0.82     0.37     2.22    0.01  
## tiltedTRUE            1.29     0.32     4.07   0.0000 
## septic_tankTRUE       -1.57    1.43     -1.10   0.13  
## conc_rainfallTRUE     1.59     0.53     3.00    0.001 
## wastewaterTRUE        0.68     0.24     2.88    0.002 
## ground_vegTRUE        0.77     0.26     3.01    0.001 
## angleD                0.07     0.49     0.14    0.44  
## angleE                0.41     0.55     0.74    0.23  
## TC_saprolite_soilTRUE 0.43     0.29     1.47    0.07  
## R1| R2                0.36     0.87     0.41    0.34  
## R2| R3                4.68     0.91     5.12   0.0000 
## R3| R4                9.81     1.01     9.73      0   
## ------------------------------------------------------

less p-value = 0.10 (TC_saprolitoTRUE,TaterroTRUE, DepTaludeAterroTRUE,DepTaludeAterroTRUE,landfillTRUE, construction_depositTRUE, leakTRUE)

par(mfrow=c(5,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
          ,data=train.data, cr=TRUE , subn=FALSE ,  cex.lab=1.5, cex.axis=2, cex.sub=2, cex.main=2)

Creating function with four level

Equation 1

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +-----------------+---+---+----+----------+------------+----------+
## |                 |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +-----------------+---+---+----+----------+------------+----------+
## |brick            |No | 38|Inf | 2.8903718| 1.673976434|-0.4274440|
## |                 |Yes|491|Inf | 2.2936565|-0.110090690|-2.1119270|
## +-----------------+---+---+----+----------+------------+----------+
## |wood             |No |455|Inf | 2.2344036|-0.207332945|-2.3122939|
## |                 |Yes| 74|Inf | 3.1640676| 1.455287233|-0.5543107|
## +-----------------+---+---+----+----------+------------+----------+
## |EN               |No |339|Inf | 1.8769173|-0.499827870|-2.3321439|
## |                 |Yes|190|Inf | 4.5432948| 0.923670839|-1.3862944|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil   |No |258|Inf | 1.9547991|-0.202236866|-2.1465808|
## |                 |Yes|271|Inf | 2.8371272| 0.185027918|-1.7245072|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction   |No |204|Inf | 1.5404450|-0.996613121|-3.0757750|
## |                 |Yes|325|Inf | 3.3514977| 0.588744061|-1.5059589|
## +-----------------+---+---+----+----------+------------+----------+
## |spring           |No |510|Inf | 2.2875795|-0.031375123|-2.0532392|
## |                 |Yes| 19|Inf |       Inf| 0.773189888| 0.1053605|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill         |No |328|Inf | 1.8647846|-0.523855124|-2.4523305|
## |                 |Yes|201|Inf | 4.1896547| 0.878289614|-1.3312346|
## +-----------------+---+---+----+----------+------------+----------+
## |leak             |No |332|Inf | 1.9322113|-0.390427231|-2.3848232|
## |                 |Yes|197|Inf | 3.6480575| 0.662841831|-1.3673664|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage          |No |346|Inf | 2.0632861|-0.279257423|-2.4298469|
## |                 |Yes|183|Inf | 3.0853444| 0.525424423|-1.2739652|
## +-----------------+---+---+----+----------+------------+----------+
## |crack            |No |447|Inf | 2.1897896|-0.292904016|-2.5625426|
## |                 |Yes| 82|Inf | 3.6888795| 2.093234864|-0.2451225|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall     |No |499|Inf | 2.2635346|-0.108322227|-2.1300270|
## |                 |Yes| 30|Inf |       Inf| 2.639057330| 0.0000000|
## +-----------------+---+---+----+----------+------------+----------+
## |scars            |No |316|Inf | 1.7697806|-1.450832882|-4.6475909|
## |                 |Yes|213|Inf | 5.3565863| 3.120895417|-0.8228250|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor   |No |466|Inf | 2.1877233|-0.267681406|-2.2116133|
## |                 |Yes| 63|Inf |       Inf| 4.127134385|-0.6225296|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted           |No |424|Inf | 2.1062528|-0.431082272|-2.6115899|
## |                 |Yes|105|Inf | 4.6443909| 2.495269437|-0.5260931|
## +-----------------+---+---+----+----------+------------+----------+
## |septic_tank      |No |527|Inf | 2.3236385| 0.003795071|-1.9095425|
## |                 |Yes|  2|Inf |       Inf|        -Inf|      -Inf|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall    |No | 19|Inf |-0.3184537|-2.890371758|      -Inf|
## |                 |Yes|510|Inf | 2.5776884| 0.062765696|-1.8718022|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater       |No |210|Inf | 1.6094379|-0.505749471|-2.8954096|
## |                 |Yes|319|Inf | 3.2419411| 0.322516025|-1.5252932|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg       |No |154|Inf | 1.3781972|-1.261131218|-2.6672282|
## |                 |Yes|375|Inf | 3.1107337| 0.461345567|-1.6984588|
## +-----------------+---+---+----+----------+------------+----------+
## |angle            |C  | 29|Inf |       Inf|-0.068992871|-3.3322045|
## |                 |D  |128|Inf | 3.4339872| 0.899941594|-1.3192837|
## |                 |E  |372|Inf | 2.0348576|-0.292387963|-2.1162555|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |448|Inf | 2.2172252|-0.062520357|-2.0521106|
## |                 |Yes| 81|Inf | 3.2580965| 0.323787077|-1.3256697|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall          |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=1, cex.sub=1)

Equation 2

  • parameters okay and so/so
  • porportion
  • excluded TC_geol_desf

f2 <- lrm(risk ~ angle + building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + drainage + TC_mature_Soil + density + TC + tree +ground_veg + deforestation + banana , data=train.data, x=TRUE , y=TRUE)

      stargazer(anova(f2), type="text", style="default")
eq_OLR_02 <- polr(risk ~ brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,
                  
                 data= train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_02))








p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                             Value Std. Error    t value      p value
## brickTRUE             -0.99839616  0.5428311 -1.8392391 3.294001e-02
## woodTRUE               1.10993097  0.3529454  3.1447663 8.310977e-04
## ENTRUE                 0.72722501  0.4012787  1.8122690 3.497232e-02
## TC_mature_soilTRUE     0.33486733  0.2337239  1.4327474 7.596502e-02
## T_constructionTRUE     0.34837533  0.3687639  0.9447110 1.724032e-01
## landfillTRUE           0.04192925  0.3282625  0.1277308 4.491810e-01
## leakTRUE              -0.15834896  0.2411727 -0.6565791 2.557258e-01
## garbageTRUE            0.23285067  0.2972795  0.7832720 2.167337e-01
## crackTRUE              1.85510225  0.3359040  5.5227162 1.668994e-08
## leaning_wallTRUE       2.27191766  0.5334917  4.2585808 1.028645e-05
## treeTRUE              -0.10955413  0.2503265 -0.4376450 3.308218e-01
## downward_floorTRUE     0.82812669  0.3670432  2.2562107 1.202872e-02
## tiltedTRUE             1.25186506  0.3181684  3.9345990 4.166785e-05
## ground_vegTRUE         0.67407659  0.2776482  2.4278085 7.595180e-03
## scarsTRUE              3.90493338  0.3568373 10.9431755 3.582282e-28
## mixedTRUE             -0.01365161  0.5350762 -0.0255134 4.898227e-01
## conc_rainfallTRUE      1.09569988  0.5699712  1.9223777 2.727913e-02
## wastewaterTRUE         0.46772797  0.2457800  1.9030349 2.851799e-02
## angleD                -0.11780506  0.4906140 -0.2401176 4.051195e-01
## angleE                 0.33276495  0.5611384  0.5930176 2.765847e-01
## bananaTRUE             0.27019701  0.2596494  1.0406224 1.490254e-01
## drainage.L             0.96971595  0.2903259  3.3400943 4.187497e-04
## drainage.Q            -0.20313331  0.1911265 -1.0628211 1.439315e-01
## TC_saprolite_soilTRUE  0.42014178  0.3008052  1.3967240 8.124829e-02
## TCTRUE                 0.44251685  0.5498729  0.8047620 2.104785e-01
## deforestationTRUE      0.51591624  0.4231407  1.2192547 1.113738e-01
## R1|R2                  0.12299067  1.1444994  0.1074624 4.572111e-01
## R2|R3                  4.62692869  1.1644256  3.9735717 3.540142e-05
## R3|R4                  9.73403071  1.2522017  7.7735327 3.816348e-15
stargazer((ctable), type="text", style="default", digits=2)
## 
## ======================================================
##                       Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE             -1.00    0.54     -1.84   0.03  
## woodTRUE              1.11     0.35     3.14    0.001 
## ENTRUE                0.73     0.40     1.81    0.03  
## TC_mature_soilTRUE    0.33     0.23     1.43    0.08  
## T_constructionTRUE    0.35     0.37     0.94    0.17  
## landfillTRUE          0.04     0.33     0.13    0.45  
## leakTRUE              -0.16    0.24     -0.66   0.26  
## garbageTRUE           0.23     0.30     0.78    0.22  
## crackTRUE             1.86     0.34     5.52   0.0000 
## leaning_wallTRUE      2.27     0.53     4.26   0.0000 
## treeTRUE              -0.11    0.25     -0.44   0.33  
## downward_floorTRUE    0.83     0.37     2.26    0.01  
## tiltedTRUE            1.25     0.32     3.93   0.0000 
## ground_vegTRUE        0.67     0.28     2.43    0.01  
## scarsTRUE             3.90     0.36     10.94     0   
## mixedTRUE             -0.01    0.54     -0.03   0.49  
## conc_rainfallTRUE     1.10     0.57     1.92    0.03  
## wastewaterTRUE        0.47     0.25     1.90    0.03  
## angleD                -0.12    0.49     -0.24   0.41  
## angleE                0.33     0.56     0.59    0.28  
## bananaTRUE            0.27     0.26     1.04    0.15  
## drainage.L            0.97     0.29     3.34   0.0004 
## drainage.Q            -0.20    0.19     -1.06   0.14  
## TC_saprolite_soilTRUE 0.42     0.30     1.40    0.08  
## TCTRUE                0.44     0.55     0.80    0.21  
## deforestationTRUE     0.52     0.42     1.22    0.11  
## R1| R2                0.12     1.14     0.11    0.46  
## R2| R3                4.63     1.16     3.97   0.0000 
## R3| R4                9.73     1.25     7.77      0   
## ------------------------------------------------------
par(mfrow=c(6,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation
          ,data=train.data, cr=TRUE , subn=FALSE ,  cex.lab=1.5, cex.axis=4, cex.sub=4, cex.main=4)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,data=train.data
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +-----------------+---+---+----+----------+------------+----------+
## |                 |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +-----------------+---+---+----+----------+------------+----------+
## |brick            |No | 38|Inf | 2.8903718| 1.673976434|-0.4274440|
## |                 |Yes|491|Inf | 2.2936565|-0.110090690|-2.1119270|
## +-----------------+---+---+----+----------+------------+----------+
## |wood             |No |455|Inf | 2.2344036|-0.207332945|-2.3122939|
## |                 |Yes| 74|Inf | 3.1640676| 1.455287233|-0.5543107|
## +-----------------+---+---+----+----------+------------+----------+
## |EN               |No |339|Inf | 1.8769173|-0.499827870|-2.3321439|
## |                 |Yes|190|Inf | 4.5432948| 0.923670839|-1.3862944|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil   |No |258|Inf | 1.9547991|-0.202236866|-2.1465808|
## |                 |Yes|271|Inf | 2.8371272| 0.185027918|-1.7245072|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction   |No |204|Inf | 1.5404450|-0.996613121|-3.0757750|
## |                 |Yes|325|Inf | 3.3514977| 0.588744061|-1.5059589|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill         |No |328|Inf | 1.8647846|-0.523855124|-2.4523305|
## |                 |Yes|201|Inf | 4.1896547| 0.878289614|-1.3312346|
## +-----------------+---+---+----+----------+------------+----------+
## |leak             |No |332|Inf | 1.9322113|-0.390427231|-2.3848232|
## |                 |Yes|197|Inf | 3.6480575| 0.662841831|-1.3673664|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage          |No |346|Inf | 2.0632861|-0.279257423|-2.4298469|
## |                 |Yes|183|Inf | 3.0853444| 0.525424423|-1.2739652|
## +-----------------+---+---+----+----------+------------+----------+
## |crack            |No |447|Inf | 2.1897896|-0.292904016|-2.5625426|
## |                 |Yes| 82|Inf | 3.6888795| 2.093234864|-0.2451225|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall     |No |499|Inf | 2.2635346|-0.108322227|-2.1300270|
## |                 |Yes| 30|Inf |       Inf| 2.639057330| 0.0000000|
## +-----------------+---+---+----+----------+------------+----------+
## |tree             |No |209|Inf | 1.7104138|-0.601209685|-2.2460147|
## |                 |Yes|320|Inf | 3.0122616| 0.379489622|-1.7346011|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor   |No |466|Inf | 2.1877233|-0.267681406|-2.2116133|
## |                 |Yes| 63|Inf |       Inf| 4.127134385|-0.6225296|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted           |No |424|Inf | 2.1062528|-0.431082272|-2.6115899|
## |                 |Yes|105|Inf | 4.6443909| 2.495269437|-0.5260931|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg       |No |154|Inf | 1.3781972|-1.261131218|-2.6672282|
## |                 |Yes|375|Inf | 3.1107337| 0.461345567|-1.6984588|
## +-----------------+---+---+----+----------+------------+----------+
## |scars            |No |316|Inf | 1.7697806|-1.450832882|-4.6475909|
## |                 |Yes|213|Inf | 5.3565863| 3.120895417|-0.8228250|
## +-----------------+---+---+----+----------+------------+----------+
## |mixed            |No |491|Inf | 2.2936565|-0.077431740|-2.0299933|
## |                 |Yes| 38|Inf | 2.8903718| 1.029619417|-0.8979416|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall    |No | 19|Inf |-0.3184537|-2.890371758|      -Inf|
## |                 |Yes|510|Inf | 2.5776884| 0.062765696|-1.8718022|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater       |No |210|Inf | 1.6094379|-0.505749471|-2.8954096|
## |                 |Yes|319|Inf | 3.2419411| 0.322516025|-1.5252932|
## +-----------------+---+---+----+----------+------------+----------+
## |angle            |C  | 29|Inf |       Inf|-0.068992871|-3.3322045|
## |                 |D  |128|Inf | 3.4339872| 0.899941594|-1.3192837|
## |                 |E  |372|Inf | 2.0348576|-0.292387963|-2.1162555|
## +-----------------+---+---+----+----------+------------+----------+
## |banana           |No |342|Inf | 1.9129039|-0.366625275|-2.3058057|
## |                 |Yes|187|Inf | 4.1163235| 0.677146839|-1.3997174|
## +-----------------+---+---+----+----------+------------+----------+
## |drainage         |Y  | 67|Inf | 0.7156200|-1.998095902|-4.1896547|
## |                 |P  |232|Inf | 2.4168532|-0.492476485|-2.5374247|
## |                 |N  |230|Inf | 3.6198866| 0.996829594|-1.2809338|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |448|Inf | 2.2172252|-0.062520357|-2.0521106|
## |                 |Yes| 81|Inf | 3.2580965| 0.323787077|-1.3256697|
## +-----------------+---+---+----+----------+------------+----------+
## |TC               |No | 26|Inf |       Inf| 0.810930216|-1.4350845|
## |                 |Yes|503|Inf | 2.2723452|-0.043744549|-1.9436400|
## +-----------------+---+---+----+----------+------------+----------+
## |deforestation    |No |494|Inf | 2.3250579| 0.048592555|-1.8870696|
## |                 |Yes| 35|Inf | 2.3671236|-0.780158558|-2.3671236|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall          |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=2, cex.sub=1)

Equation 3

  • parameters okay and so/so
  • porportion
  • p-value based equation 2 > 0.5

f3 <- lrm(risk ~ angle +building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree + TC , data=train.data, x=TRUE , y=TRUE) stargazer(anova(f3), type=“text”, style=“default”)

# x=TRUE, y=TRUE used by resid() below 

eq_OLR_03 <- polr(risk ~ wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, data=train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_03))


p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                          Value Std. Error    t value      p value
## woodTRUE            1.28818143  0.3280250  3.9270834 4.299108e-05
## TC_mature_soilTRUE  0.38543801  0.2204994  1.7480228 4.023004e-02
## T_constructionTRUE  0.48538416  0.2990911  1.6228640 5.230924e-02
## landfillTRUE       -0.05353937  0.2924927 -0.1830452 4.273813e-01
## crackTRUE           1.83781197  0.3236920  5.6776558 6.827657e-09
## leaning_wallTRUE    2.32739513  0.5301272  4.3902579 5.660815e-06
## treeTRUE           -0.05983224  0.2403399 -0.2489485 4.017003e-01
## downward_floorTRUE  0.81419597  0.3530841  2.3059548 1.055658e-02
## tiltedTRUE          1.26843267  0.3117441  4.0688263 2.362528e-05
## ground_vegTRUE      0.65395947  0.2693572  2.4278522 7.594265e-03
## scarsTRUE           3.85857762  0.3520260 10.9610574 2.940411e-28
## conc_rainfallTRUE   1.17311115  0.5605247  2.0928806 1.817991e-02
## wastewaterTRUE      0.46397067  0.2400519  1.9327930 2.663085e-02
## bananaTRUE          0.33372748  0.2470893  1.3506350 8.840619e-02
## drainage.L          0.93781055  0.2811345  3.3358072 4.252606e-04
## drainage.Q         -0.17476018  0.1890862 -0.9242353 1.776819e-01
## R1|R2               0.34489485  0.5452334  0.6325637 2.635093e-01
## R2|R3               4.73301097  0.6032375  7.8460164 2.147304e-15
## R3|R4               9.76851921  0.7444785 13.1212920 1.243296e-39
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE           1.29     0.33     3.93   0.0000 
## TC_mature_soilTRUE 0.39     0.22     1.75    0.04  
## T_constructionTRUE 0.49     0.30     1.62    0.05  
## landfillTRUE       -0.05    0.29     -0.18   0.43  
## crackTRUE          1.84     0.32     5.68      0   
## leaning_wallTRUE   2.33     0.53     4.39   0.0000 
## treeTRUE           -0.06    0.24     -0.25   0.40  
## downward_floorTRUE 0.81     0.35     2.31    0.01  
## tiltedTRUE         1.27     0.31     4.07   0.0000 
## ground_vegTRUE     0.65     0.27     2.43    0.01  
## scarsTRUE          3.86     0.35     10.96     0   
## conc_rainfallTRUE  1.17     0.56     2.09    0.02  
## wastewaterTRUE     0.46     0.24     1.93    0.03  
## bananaTRUE         0.33     0.25     1.35    0.09  
## drainage.L         0.94     0.28     3.34   0.0004 
## drainage.Q         -0.17    0.19     -0.92   0.18  
## R1| R2             0.34     0.55     0.63    0.26  
## R2| R3             4.73     0.60     7.85      0   
## R3| R4             9.77     0.74     13.12     0   
## ---------------------------------------------------
#print (f3 , latex =TRUE , coefs =5)
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~  wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage,,
          data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |455|Inf | 2.2344036|-0.207332945|-2.3122939|
## |              |Yes| 74|Inf | 3.1640676| 1.455287233|-0.5543107|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |258|Inf | 1.9547991|-0.202236866|-2.1465808|
## |              |Yes|271|Inf | 2.8371272| 0.185027918|-1.7245072|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |204|Inf | 1.5404450|-0.996613121|-3.0757750|
## |              |Yes|325|Inf | 3.3514977| 0.588744061|-1.5059589|
## +--------------+---+---+----+----------+------------+----------+
## |landfill      |No |328|Inf | 1.8647846|-0.523855124|-2.4523305|
## |              |Yes|201|Inf | 4.1896547| 0.878289614|-1.3312346|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |447|Inf | 2.1897896|-0.292904016|-2.5625426|
## |              |Yes| 82|Inf | 3.6888795| 2.093234864|-0.2451225|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |499|Inf | 2.2635346|-0.108322227|-2.1300270|
## |              |Yes| 30|Inf |       Inf| 2.639057330| 0.0000000|
## +--------------+---+---+----+----------+------------+----------+
## |tree          |No |209|Inf | 1.7104138|-0.601209685|-2.2460147|
## |              |Yes|320|Inf | 3.0122616| 0.379489622|-1.7346011|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |466|Inf | 2.1877233|-0.267681406|-2.2116133|
## |              |Yes| 63|Inf |       Inf| 4.127134385|-0.6225296|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |424|Inf | 2.1062528|-0.431082272|-2.6115899|
## |              |Yes|105|Inf | 4.6443909| 2.495269437|-0.5260931|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |154|Inf | 1.3781972|-1.261131218|-2.6672282|
## |              |Yes|375|Inf | 3.1107337| 0.461345567|-1.6984588|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |316|Inf | 1.7697806|-1.450832882|-4.6475909|
## |              |Yes|213|Inf | 5.3565863| 3.120895417|-0.8228250|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 19|Inf |-0.3184537|-2.890371758|      -Inf|
## |              |Yes|510|Inf | 2.5776884| 0.062765696|-1.8718022|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |210|Inf | 1.6094379|-0.505749471|-2.8954096|
## |              |Yes|319|Inf | 3.2419411| 0.322516025|-1.5252932|
## +--------------+---+---+----+----------+------------+----------+
## |banana        |No |342|Inf | 1.9129039|-0.366625275|-2.3058057|
## |              |Yes|187|Inf | 4.1163235| 0.677146839|-1.3997174|
## +--------------+---+---+----+----------+------------+----------+
## |drainage      |Y  | 67|Inf | 0.7156200|-1.998095902|-4.1896547|
## |              |P  |232|Inf | 2.4168532|-0.492476485|-2.5374247|
## |              |N  |230|Inf | 3.6198866| 0.996829594|-1.2809338|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.6, cex.axis=0.6, cex.sub=0.6)

Equation 4

  • p-value equation 3 > 0.05 (banana, DepTaludeCorte)
  • consider proportion
  • paremeters okay & so/so
  • fashion order

f4 <- lrm(risk ~ building + EN
+ DepEncNatural
+ crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + drainage + TC_mature_Soil + TC + +ground_veg
,data=train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f4), type=“text”, style=“default”)

eq_OLR_04 <- polr(risk~ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
                  , data= train.data
           ,  method = "logistic", Hess = TRUE)
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value

ctable <- coef(summary(eq_OLR_04))

ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
##                          Value Std. Error    t value      p value
## woodTRUE            1.28904486  0.3280559  3.9293456 4.299108e-05
## TC_mature_soilTRUE  0.39131811  0.2181114  1.7941207 4.023004e-02
## T_constructionTRUE  0.45322812  0.2424371  1.8694668 5.230924e-02
## crackTRUE           1.83090006  0.3213710  5.6971535 4.273813e-01
## leaning_wallTRUE    2.32773256  0.5296259  4.3950504 6.827657e-09
## treeTRUE           -0.05553275  0.2391493 -0.2322095 5.660815e-06
## downward_floorTRUE  0.80482047  0.3493043  2.3040670 4.017003e-01
## tiltedTRUE          1.25834755  0.3066457  4.1035884 1.055658e-02
## ground_vegTRUE      0.65085487  0.2688644  2.4207548 2.362528e-05
## scarsTRUE           3.85994351  0.3519907 10.9660376 7.594265e-03
## conc_rainfallTRUE   1.16931455  0.5600302  2.0879490 2.940411e-28
## wastewaterTRUE      0.47142433  0.2364497  1.9937616 1.817991e-02
## bananaTRUE          0.33191296  0.2468574  1.3445532 2.663085e-02
## drainage.L          0.93412470  0.2804480  3.3308302 8.840619e-02
## drainage.Q         -0.17524330  0.1890681 -0.9268791 4.252606e-04
## R1|R2               0.34576736  0.5449837  0.6344545 1.776819e-01
## R2|R3               4.73315749  0.6030061  7.8492700 2.635093e-01
## R3|R4               9.76920907  0.7442335 13.1265374 2.147304e-15
stargazer((ctable), type="text", style="default", digits=2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE           1.29     0.33     3.93   0.0000 
## TC_mature_soilTRUE 0.39     0.22     1.79    0.04  
## T_constructionTRUE 0.45     0.24     1.87    0.05  
## crackTRUE          1.83     0.32     5.70    0.43  
## leaning_wallTRUE   2.33     0.53     4.40      0   
## treeTRUE           -0.06    0.24     -0.23  0.0000 
## downward_floorTRUE 0.80     0.35     2.30    0.40  
## tiltedTRUE         1.26     0.31     4.10    0.01  
## ground_vegTRUE     0.65     0.27     2.42   0.0000 
## scarsTRUE          3.86     0.35     10.97   0.01  
## conc_rainfallTRUE  1.17     0.56     2.09      0   
## wastewaterTRUE     0.47     0.24     1.99    0.02  
## bananaTRUE         0.33     0.25     1.34    0.03  
## drainage.L         0.93     0.28     3.33    0.09  
## drainage.Q         -0.18    0.19     -0.93  0.0004 
## R1| R2             0.35     0.54     0.63    0.18  
## R2| R3             4.73     0.60     7.85    0.26  
## R3| R4             9.77     0.74     13.13     0   
## ---------------------------------------------------
par(mfrow=c(4,4))
plot.xmean.ordinaly (risk ~  wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |455|Inf | 2.2344036|-0.207332945|-2.3122939|
## |              |Yes| 74|Inf | 3.1640676| 1.455287233|-0.5543107|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |258|Inf | 1.9547991|-0.202236866|-2.1465808|
## |              |Yes|271|Inf | 2.8371272| 0.185027918|-1.7245072|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |204|Inf | 1.5404450|-0.996613121|-3.0757750|
## |              |Yes|325|Inf | 3.3514977| 0.588744061|-1.5059589|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |447|Inf | 2.1897896|-0.292904016|-2.5625426|
## |              |Yes| 82|Inf | 3.6888795| 2.093234864|-0.2451225|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |499|Inf | 2.2635346|-0.108322227|-2.1300270|
## |              |Yes| 30|Inf |       Inf| 2.639057330| 0.0000000|
## +--------------+---+---+----+----------+------------+----------+
## |tree          |No |209|Inf | 1.7104138|-0.601209685|-2.2460147|
## |              |Yes|320|Inf | 3.0122616| 0.379489622|-1.7346011|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |466|Inf | 2.1877233|-0.267681406|-2.2116133|
## |              |Yes| 63|Inf |       Inf| 4.127134385|-0.6225296|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |424|Inf | 2.1062528|-0.431082272|-2.6115899|
## |              |Yes|105|Inf | 4.6443909| 2.495269437|-0.5260931|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |154|Inf | 1.3781972|-1.261131218|-2.6672282|
## |              |Yes|375|Inf | 3.1107337| 0.461345567|-1.6984588|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |316|Inf | 1.7697806|-1.450832882|-4.6475909|
## |              |Yes|213|Inf | 5.3565863| 3.120895417|-0.8228250|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 19|Inf |-0.3184537|-2.890371758|      -Inf|
## |              |Yes|510|Inf | 2.5776884| 0.062765696|-1.8718022|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |210|Inf | 1.6094379|-0.505749471|-2.8954096|
## |              |Yes|319|Inf | 3.2419411| 0.322516025|-1.5252932|
## +--------------+---+---+----+----------+------------+----------+
## |banana        |No |342|Inf | 1.9129039|-0.366625275|-2.3058057|
## |              |Yes|187|Inf | 4.1163235| 0.677146839|-1.3997174|
## +--------------+---+---+----+----------+------------+----------+
## |drainage      |Y  | 67|Inf | 0.7156200|-1.998095902|-4.1896547|
## |              |P  |232|Inf | 2.4168532|-0.492476485|-2.5374247|
## |              |N  |230|Inf | 3.6198866| 0.996829594|-1.2809338|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

Equation 5 - Based on Equation 1

  • based on Eq 1
  • less p-value > 0.10 (
# x=TRUE, y=TRUE used by resid() below 
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")

eq_OLR_05 <- polr(risk ~ brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg,  data= train.data
           ,  method = "logistic", Hess = TRUE)

ctable <- coef(summary(eq_OLR_05))

p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                          Value Std. Error    t value      p value
## brickTRUE          -0.94633319  0.4418507 -2.1417489 1.610685e-02
## woodTRUE            1.32844131  0.3262925  4.0713201 2.337373e-05
## TC_mature_soilTRUE  0.41708740  0.2151759  1.9383559 2.628991e-02
## T_constructionTRUE  0.46743526  0.2369222  1.9729482 2.425073e-02
## crackTRUE           1.77127862  0.3183722  5.5635475 1.321724e-08
## leaning_wallTRUE    2.24411392  0.5265558  4.2618733 1.013602e-05
## scarsTRUE           3.97274027  0.3533932 11.2417007 1.272164e-29
## downward_floorTRUE  0.86649559  0.3527597  2.4563338 7.018135e-03
## tiltedTRUE          1.37252008  0.3059474  4.4861306 3.626415e-06
## conc_rainfallTRUE   1.66853924  0.5243323  3.1822169 7.307617e-04
## wastewaterTRUE      0.62290661  0.2296618  2.7122780 3.341127e-03
## ground_vegTRUE      0.90000203  0.2434713  3.6965420 1.092781e-04
## R1|R2               0.07686802  0.6656727  0.1154742 4.540346e-01
## R2|R3               4.31988276  0.7196337  6.0028912 9.691726e-10
## R3|R4               9.39977784  0.8258966 11.3813014 2.591031e-30
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE          -0.95    0.44     -2.14   0.02  
## woodTRUE           1.33     0.33     4.07   0.0000 
## TC_mature_soilTRUE 0.42     0.22     1.94    0.03  
## T_constructionTRUE 0.47     0.24     1.97    0.02  
## crackTRUE          1.77     0.32     5.56      0   
## leaning_wallTRUE   2.24     0.53     4.26   0.0000 
## scarsTRUE          3.97     0.35     11.24     0   
## downward_floorTRUE 0.87     0.35     2.46    0.01  
## tiltedTRUE         1.37     0.31     4.49   0.0000 
## conc_rainfallTRUE  1.67     0.52     3.18    0.001 
## wastewaterTRUE     0.62     0.23     2.71    0.003 
## ground_vegTRUE     0.90     0.24     3.70   0.0001 
## R1| R2             0.08     0.67     0.12    0.45  
## R2| R3             4.32     0.72     6.00      0   
## R3| R4             9.40     0.83     11.38     0   
## ---------------------------------------------------
par(mfrow=c(3,4))
plot.xmean.ordinaly (risk ~  brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |brick         |No | 38|Inf | 2.8903718| 1.673976434|-0.4274440|
## |              |Yes|491|Inf | 2.2936565|-0.110090690|-2.1119270|
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |455|Inf | 2.2344036|-0.207332945|-2.3122939|
## |              |Yes| 74|Inf | 3.1640676| 1.455287233|-0.5543107|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |258|Inf | 1.9547991|-0.202236866|-2.1465808|
## |              |Yes|271|Inf | 2.8371272| 0.185027918|-1.7245072|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |204|Inf | 1.5404450|-0.996613121|-3.0757750|
## |              |Yes|325|Inf | 3.3514977| 0.588744061|-1.5059589|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |447|Inf | 2.1897896|-0.292904016|-2.5625426|
## |              |Yes| 82|Inf | 3.6888795| 2.093234864|-0.2451225|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |499|Inf | 2.2635346|-0.108322227|-2.1300270|
## |              |Yes| 30|Inf |       Inf| 2.639057330| 0.0000000|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |316|Inf | 1.7697806|-1.450832882|-4.6475909|
## |              |Yes|213|Inf | 5.3565863| 3.120895417|-0.8228250|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |466|Inf | 2.1877233|-0.267681406|-2.2116133|
## |              |Yes| 63|Inf |       Inf| 4.127134385|-0.6225296|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |424|Inf | 2.1062528|-0.431082272|-2.6115899|
## |              |Yes|105|Inf | 4.6443909| 2.495269437|-0.5260931|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 19|Inf |-0.3184537|-2.890371758|      -Inf|
## |              |Yes|510|Inf | 2.5776884| 0.062765696|-1.8718022|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |210|Inf | 1.6094379|-0.505749471|-2.8954096|
## |              |Yes|319|Inf | 3.2419411| 0.322516025|-1.5252932|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |154|Inf | 1.3781972|-1.261131218|-2.6672282|
## |              |Yes|375|Inf | 3.1107337| 0.461345567|-1.6984588|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

OLR Equation 6

# x=TRUE, y=TRUE used by resid() below 
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")

eq_OLR_06 <- polr(risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana,  data= train.data
           ,  method = "logistic", Hess = TRUE)

ctable <- coef(summary(eq_OLR_06))

p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                          Value Std. Error    t value      p value
## brickTRUE          -1.18019664  0.5346808 -2.2072921 1.364683e-02
## woodTRUE            1.16496612  0.3360451  3.4666954 2.634493e-04
## mixedTRUE           0.10829211  0.5229322  0.2070863 4.179712e-01
## ENTRUE              0.88184759  0.3946729  2.2343759 1.272918e-02
## TCTRUE              0.72915922  0.5190235  1.4048674 8.003035e-02
## T_constructionTRUE  0.26513259  0.3556993  0.7453842 2.280198e-01
## landfillTRUE        0.16242865  0.3156518  0.5145817 3.034227e-01
## leakTRUE            0.03822058  0.2331227  0.1639505 4.348851e-01
## garbageTRUE         0.23317558  0.2896901  0.8049139 2.104347e-01
## crackTRUE           1.76180463  0.3283290  5.3659726 4.025708e-08
## leaning_wallTRUE    2.35218395  0.5361686  4.3870232 5.745627e-06
## treeTRUE           -0.06300889  0.2428688 -0.2594359 3.976495e-01
## tiltedTRUE          1.37759653  0.3131828  4.3986978 5.445116e-06
## angleD              0.07871442  0.4866540  0.1617462 4.357529e-01
## angleE              0.54025202  0.5546598  0.9740240 1.650223e-01
## ground_vegTRUE      0.80974449  0.2646215  3.0600105 1.106646e-03
## scarsTRUE           3.99537267  0.3547774 11.2616311 1.014833e-29
## conc_rainfallTRUE   1.79047230  0.5284973  3.3878549 3.522076e-04
## wastewaterTRUE      0.59574614  0.2347552  2.5377330 5.578653e-03
## bananaTRUE          0.30350978  0.2547587  1.1913620 1.167558e-01
## R1|R2               1.07788542  1.0897206  0.9891392 1.612975e-01
## R2|R3               5.33027409  1.1260264  4.7337024 1.102304e-06
## R3|R4              10.39993583  1.2140931  8.5660116 5.356556e-18
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE          -1.18    0.53     -2.21   0.01  
## woodTRUE           1.16     0.34     3.47   0.0003 
## mixedTRUE          0.11     0.52     0.21    0.42  
## ENTRUE             0.88     0.39     2.23    0.01  
## TCTRUE             0.73     0.52     1.40    0.08  
## T_constructionTRUE 0.27     0.36     0.75    0.23  
## landfillTRUE       0.16     0.32     0.51    0.30  
## leakTRUE           0.04     0.23     0.16    0.43  
## garbageTRUE        0.23     0.29     0.80    0.21  
## crackTRUE          1.76     0.33     5.37   0.0000 
## leaning_wallTRUE   2.35     0.54     4.39   0.0000 
## treeTRUE           -0.06    0.24     -0.26   0.40  
## tiltedTRUE         1.38     0.31     4.40   0.0000 
## angleD             0.08     0.49     0.16    0.44  
## angleE             0.54     0.55     0.97    0.17  
## ground_vegTRUE     0.81     0.26     3.06    0.001 
## scarsTRUE          4.00     0.35     11.26     0   
## conc_rainfallTRUE  1.79     0.53     3.39   0.0004 
## wastewaterTRUE     0.60     0.23     2.54    0.01  
## bananaTRUE         0.30     0.25     1.19    0.12  
## R1| R2             1.08     1.09     0.99    0.16  
## R2| R3             5.33     1.13     4.73   0.0000 
## R3| R4             10.40    1.21     8.57      0   
## ---------------------------------------------------
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk ~  brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |brick         |No | 38|Inf | 2.8903718| 1.673976434|-0.4274440|
## |              |Yes|491|Inf | 2.2936565|-0.110090690|-2.1119270|
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |455|Inf | 2.2344036|-0.207332945|-2.3122939|
## |              |Yes| 74|Inf | 3.1640676| 1.455287233|-0.5543107|
## +--------------+---+---+----+----------+------------+----------+
## |mixed         |No |491|Inf | 2.2936565|-0.077431740|-2.0299933|
## |              |Yes| 38|Inf | 2.8903718| 1.029619417|-0.8979416|
## +--------------+---+---+----+----------+------------+----------+
## |EN            |No |339|Inf | 1.8769173|-0.499827870|-2.3321439|
## |              |Yes|190|Inf | 4.5432948| 0.923670839|-1.3862944|
## +--------------+---+---+----+----------+------------+----------+
## |TC            |No | 26|Inf |       Inf| 0.810930216|-1.4350845|
## |              |Yes|503|Inf | 2.2723452|-0.043744549|-1.9436400|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |204|Inf | 1.5404450|-0.996613121|-3.0757750|
## |              |Yes|325|Inf | 3.3514977| 0.588744061|-1.5059589|
## +--------------+---+---+----+----------+------------+----------+
## |landfill      |No |328|Inf | 1.8647846|-0.523855124|-2.4523305|
## |              |Yes|201|Inf | 4.1896547| 0.878289614|-1.3312346|
## +--------------+---+---+----+----------+------------+----------+
## |leak          |No |332|Inf | 1.9322113|-0.390427231|-2.3848232|
## |              |Yes|197|Inf | 3.6480575| 0.662841831|-1.3673664|
## +--------------+---+---+----+----------+------------+----------+
## |garbage       |No |346|Inf | 2.0632861|-0.279257423|-2.4298469|
## |              |Yes|183|Inf | 3.0853444| 0.525424423|-1.2739652|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |447|Inf | 2.1897896|-0.292904016|-2.5625426|
## |              |Yes| 82|Inf | 3.6888795| 2.093234864|-0.2451225|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |499|Inf | 2.2635346|-0.108322227|-2.1300270|
## |              |Yes| 30|Inf |       Inf| 2.639057330| 0.0000000|
## +--------------+---+---+----+----------+------------+----------+
## |tree          |No |209|Inf | 1.7104138|-0.601209685|-2.2460147|
## |              |Yes|320|Inf | 3.0122616| 0.379489622|-1.7346011|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |424|Inf | 2.1062528|-0.431082272|-2.6115899|
## |              |Yes|105|Inf | 4.6443909| 2.495269437|-0.5260931|
## +--------------+---+---+----+----------+------------+----------+
## |angle         |C  | 29|Inf |       Inf|-0.068992871|-3.3322045|
## |              |D  |128|Inf | 3.4339872| 0.899941594|-1.3192837|
## |              |E  |372|Inf | 2.0348576|-0.292387963|-2.1162555|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |154|Inf | 1.3781972|-1.261131218|-2.6672282|
## |              |Yes|375|Inf | 3.1107337| 0.461345567|-1.6984588|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |316|Inf | 1.7697806|-1.450832882|-4.6475909|
## |              |Yes|213|Inf | 5.3565863| 3.120895417|-0.8228250|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 19|Inf |-0.3184537|-2.890371758|      -Inf|
## |              |Yes|510|Inf | 2.5776884| 0.062765696|-1.8718022|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |210|Inf | 1.6094379|-0.505749471|-2.8954096|
## |              |Yes|319|Inf | 3.2419411| 0.322516025|-1.5252932|
## +--------------+---+---+----+----------+------------+----------+
## |banana        |No |342|Inf | 1.9129039|-0.366625275|-2.3058057|
## |              |Yes|187|Inf | 4.1163235| 0.677146839|-1.3997174|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

Predicion on test data Eq 1: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel1 <- predict(eq_OLR_01, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_01, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel1)
##     predictedLevel1
##      R1 R2 R3 R4
##   R1  3 16  0  0
##   R2  1 86  6  0
##   R3  0 25 50  9
##   R4  0  0 17 11
p1 <- mean(as.character(test.data$risk) != as.character(predictedLevel1)) #misclassification error
p1 
## [1] 0.3303571

Predicion on test data Eq 2: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel2 <- predict(eq_OLR_02, test.data) # predict the levels directly

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel2)
##     predictedLevel2
##      R1 R2 R3 R4
##   R1  4 15  0  0
##   R2  2 85  6  0
##   R3  0 23 51 10
##   R4  0  0 16 12
p2 <- mean(as.character(test.data$risk) != as.character(predictedLevel2))
p2
## [1] 0.3214286

Predicion on test data Eq 3: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel3 <- predict(eq_OLR_03, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_03, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel3)
##     predictedLevel3
##      R1 R2 R3 R4
##   R1  3 16  0  0
##   R2  2 86  5  0
##   R3  0 25 50  9
##   R4  0  0 15 13
p3 <- mean(as.character(test.data$risk) != as.character(predictedLevel3))
p3
## [1] 0.3214286

Predicion on test data Eq 4: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel4 <- predict(eq_OLR_04, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_04, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel4)
##     predictedLevel4
##      R1 R2 R3 R4
##   R1  3 16  0  0
##   R2  2 86  5  0
##   R3  0 25 50  9
##   R4  0  0 15 13
p4 <- mean(as.character(test.data$risk) != as.character(predictedLevel4))
p4
## [1] 0.3214286

Predicion on test data Eq 5: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel5 <- predict(eq_OLR_05, test.data) # predict the levels directly

predictedScores5 <- predict(eq_OLR_05, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel5)
##     predictedLevel5
##      R1 R2 R3 R4
##   R1  3 16  0  0
##   R2  2 84  7  0
##   R3  0 24 51  9
##   R4  0  0 15 13
p5 <- mean(as.character(test.data$risk) != as.character(predictedLevel5))
p5
## [1] 0.3258929

Predicion on test data Eq 6: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel6 <- predict(eq_OLR_06, test.data) # predict the levels directly

predictedScores6 <- predict(eq_OLR_06, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel6)
##     predictedLevel6
##      R1 R2 R3 R4
##   R1  2 17  0  0
##   R2  1 86  6  0
##   R3  0 25 50  9
##   R4  0  0 17 11
p6 <- mean(as.character(test.data$risk) != as.character(predictedLevel6))
p6
## [1] 0.3348214

Predicion on test data Eq 7: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

#Table 

df2 <- data.frame(
  
  "Equations"=c(1:6), 
  "Predicted"=c(1-p1, 
                1-p2,
                1-p3,
                1-p4,
                1-p5,
                1-p6
               
              
    
    
  )
  
  
  
)

df2
##   Equations Predicted
## 1         1 0.6696429
## 2         2 0.6785714
## 3         3 0.6785714
## 4         4 0.6785714
## 5         5 0.6741071
## 6         6 0.6651786